package com.ferryc.codgen;

import com.ferryc.codgen.model.InOutType;
import com.ferryc.codgen.model.OutputModel;
import com.ferryc.codgen.service.Builder;
import com.ferryc.codgen.service.impl.CodeBuilder;
import com.ferryc.codgen.service.impl.ProjectBuildConfig;
import com.ferryc.codgen.util.ProjectConfig;
import com.ferryc.codgen.util.ProjectConfigHelper;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import java.io.File;
import java.util.Map;
import java.util.Map.Entry;

import static org.junit.Assert.assertTrue;

public class CodeBuilderTest {
	ProjectBuildConfig buildConfig;

	@Before
	public void setUp() throws Exception {
	}

	@After
	public void tearDown() throws Exception {
		Builder builder = new CodeBuilder(buildConfig);
		Map<String, OutputModel> omMap = builder.build();
		for (Entry<String, OutputModel> entry : omMap.entrySet()) {
			// System.out.println("生成内容="+entry.getValue().getOutput());
			if (entry.getValue().getType() == InOutType.FILE) {
				assertTrue("文件没有生成=" + entry.getValue().getOutput(), new File(entry.getValue().getOutput()).exists());
			}
		}
	}

	@Test
	public void testBuild() {
		try {
			ProjectConfig projectConfig = ProjectConfigHelper.getDefaultProjectConfig(null);

			buildConfig = new ProjectBuildConfig(projectConfig);
			buildConfig.setTableName("tb_user");
			buildConfig.setPageName("tb");
			buildConfig.setViewDir("user");
		} catch (Exception e) {
			e.printStackTrace();
		}

	}

}
